home *** CD-ROM | disk | FTP | other *** search
- /*
- These are routines called by the %_BP and %_EP routines in
- BP_EP.a. Those routines replace the ones in the library,
- and enable the user to implement their own debugger.
-
- Author: Marshall Clow
-
- Log:
- Jun 02, 1992 new file.
- */
-
- #include "BP_EP.h"
-
- #include <Memory.h>
-
-
- /* Override this procedure to control breaking into the debugger */
- #pragma trace off
- Boolean BreakHere ( void ) {
- return false;
- }
-
-
- #pragma trace off
- Boolean IsValidSymbolChar ( char ch ) {
- if ( ch >= 'A' && ch <= 'Z' )
- return true;
- if ( ch >= 'a' && ch <= 'z' )
- return true;
- if ( ch >= '0' && ch <= '9' )
- return true;
- return ch == '_' || ch == '%' || ch == ' ';
- }
-
-
- /*
- From DisAsmLookup.h:
- A valid MacsBug symbol consists of the characters '_', '%', spaces, digits, and
- upper/lower case letters in a format determined by the first two bytes of the
- symbol as follows:
-
- 1st byte | 2nd byte | Byte |
- Range | Range | Length | Comments
- ==============================================================================
- (1) $20 - $7F | $20 - $7F | 8 | "Old style" MacsBug symbol format
- $A0 - $FF | $20 - $7F | 8 | "Old style" MacsBug symbol format
- ------------------------------------------------------------------------------
- (2) $20 - $7F | $80 - $FF | 16 | "Old style" MacApp symbol ab==>b.a
- $A0 - $FF | $80 - $FF | 16 | "Old style" MacApp symbol ab==>b.a
- ------------------------------------------------------------------------------
- (3) $80 | $01 - $FF | n | n = 2nd byte (Apple Compiler symbol)
- (4) $81 - $9F | $00 - $FF | m | m = 1st byte & $7F (Apple Compiler symbol)
- ==============================================================================
- */
-
- enum {
- kStyleUndef,
- kStyle8,
- kStyle16,
- kStyle80,
- kStyle81Up
- };
-
- typedef unsigned short TMacsBugStyles;
-
- #pragma trace off
- Boolean IsMacsBugName ( void *theCode, Str255 theName ) {
- TMacsBugStyles theStyle = kStyleUndef;
- Ptr codePtr = theCode;
- unsigned char firstChar = *codePtr;
- unsigned char secondChar = codePtr [ 1 ];
- short i, length;
-
-
- /* Identify the type of Symbol */
- if ( firstChar == 0x80 )
- theStyle = kStyle80;
- else if ( firstChar > 0x80 && firstChar < 0xA0 )
- theStyle = kStyle81Up;
- else
- theStyle = secondChar >= 0x80 && secondChar <= 0xFF ? kStyle16 : kStyle8;
-
- if ( theStyle == kStyleUndef )
- return false;
-
- /* Build the Symbol */
- switch ( theStyle ) {
- case kStyle8:
- BlockMove ( codePtr, theName + 1, 8 );
- theName [ 0 ] = 8;
- theName [ 1 ] &= 0x7F;
- break;
-
- case kStyle16:
- theName [ 0 ] = 17;
- theName [ 9 ] = '%';
- BlockMove ( codePtr, theName + 10, 8 );
- BlockMove ( codePtr + 8, theName + 1, 8 );
- theName [ 1 ] &= 0x7F;
- theName [ 10 ] &= 0x7F;
- break;
-
- case kStyle80:
- BlockMove ( codePtr + 1, theName, codePtr [ 1 ] );
- break;
-
- case kStyle81Up:
- length = *codePtr & 0x7F;
- BlockMove ( codePtr, theName, length + 1 );
- theName [ 0 ] = length;
- break;
-
- default:
- DebugStr ( "\pBad Style" );
- break;
- }
-
- i = theStyle;
- for ( i = 1; i <= theName [ 0 ]; i++ )
- if ( !IsValidSymbolChar ( theName [ i ] ))
- return false;
- return true;
- }
-
-
- /*
- Also From DisAsmLookup.h:
- Check to see if the specified memory address, contains a RTS, JMP (A0) or
- RTD #n instruction immediately followed by a valid MacsBug symbol. These
- sequences are the only ones which can determine an end of module when MacsBug
- symbols are present.
- */
-
- #define kRTS 0x4E75
- #define kJMPA0 0x4ED0
- #define kRTDn 0x4E74
- #define kMaxModuleWords 0x0400
-
- #pragma trace off
- Boolean FindMacsBugName ( void *theCode, Str255 theName ) {
- short *codePtr = theCode;
- short *limitPtr = codePtr + kMaxModuleWords;
-
- while ( codePtr < limitPtr ) {
- switch ( *codePtr ) {
- case kRTDn:
- codePtr++;
- case kRTS:
- case kJMPA0:
- codePtr++;
- if ( IsMacsBugName ( codePtr, theName ))
- return true;
-
- default:
- break;
- }
-
- codePtr++;
- }
-
- return false;
- }
-